/*
 * @Author: your name
 * @Date: 2020-06-13 20:16:46
 * @LastEditTime: 2020-06-13 20:46:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \undefinede:\leetcode刷题\500.键盘行.cpp
 */
/*
 * @lc app=leetcode.cn id=500 lang=cpp
 *
 * [500] 键盘行
 */

// @lc code=start
class Solution
{
public:
    vector<string> findWords(vector<string> &words)
    {
        unordered_set<char> set1{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'};
        unordered_set<char> set2{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'};
        unordered_set<char> set3{'z', 'x', 'c', 'v', 'b', 'n', 'm'};
        vector<string> res;

        for (string word : words)
        {
            bool flag = true;
            unordered_set<char> setTemp;

            if (set1.find(tolower(word[0])) != set1.end())
            {
                setTemp = set1;
            }
            else if (set2.find(tolower(word[0])) != set2.end())
            {
                setTemp = set2;
            }
            else
                setTemp = set3;

            for (char ch : word)
            {
                if (setTemp.find(tolower(ch)) == setTemp.end())
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
                res.push_back(word);
        }

        return res;
    }
};
// @lc code=end
